package com.sto.stoapp.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.sto.stoapp.activity.R;
import com.sto.stoapp.entity.BillControls;

import java.util.List;

/**
 * Created by wj on 2016-12-29.
 */

public class BillControlsAdapter extends BaseAdapter{

    private List<BillControls.RulesBean> datas;
    private Context context;

    public BillControlsAdapter(List<BillControls.RulesBean> datas, Context context) {
        this.datas = datas;
        this.context = context;
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder=null;

        if(convertView==null){
            holder=new ViewHolder();
            convertView= LayoutInflater.from(context).inflate(R.layout.item_bill_controls,
                    parent,false);
            holder.startTV= (TextView) convertView.findViewById(R.id.tv_start);
            holder.endTV= (TextView) convertView.findViewById(R.id.tv_end);
            holder.numTV= (TextView) convertView.findViewById(R.id.tv_num);
            holder.timeTV= (TextView) convertView.findViewById(R.id.tv_time);
            convertView.setTag(holder);
        }else {
            holder= (ViewHolder) convertView.getTag();
        }

        BillControls.RulesBean bean=datas.get(position);

        holder.startTV.setText(bean.getStartNo());
        holder.endTV.setText(bean.getEndNo());
        int num= (int) (Double.valueOf(bean.getEndNo())-Double.valueOf(bean.getStartNo()));
        holder.numTV.setText(num+"");
        holder.timeTV.setText(bean.getEndTime());

        return convertView;
    }

    class ViewHolder{

        private TextView startTV;
        private TextView endTV;
        private TextView numTV;
        private TextView timeTV;

    }
}
